<template>
    <div id="box">
          <!--面包屑区域-->
    <el-breadcrumb separator-class="el-icon-arrow-right">
  <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
  <el-breadcrumb-item>订单管理</el-breadcrumb-item>
  <el-breadcrumb-item>订单列表</el-breadcrumb-item>
</el-breadcrumb> 
<!--卡片视图-->
 <el-card>
   <el-row>
    <el-col :span="8">
        <el-input placeholder="请输入内容" >
    <el-button slot="append" icon="el-icon-search" ></el-button>
  </el-input>
    </el-col>
   </el-row>

   <el-table :data="orderList" border stripe>
    <el-table-column label="#" type="index"></el-table-column>
      <el-table-column prop="order_number" label="订单编号"></el-table-column>
      <el-table-column prop="order_price" label="订单价格"></el-table-column>
      <el-table-column prop="pay_status" label="是否付款">
        <template v-slot="scope">
        <el-tag type="success" v-if="scope.row.pay_status==='1'">已付款</el-tag>
        <el-tag type="danger" v-else>未付款</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="is_send" label="是否发货"></el-table-column>
      <el-table-column prop="create_time" label="下单时间">
        <template v-slot="scope">
        {{  scope.row.create_time | dateFormat  }}
            </template>
      </el-table-column>
      <el-table-column label="操作">
        <template v-slot="scope">
            <el-tooltip class="item" effect="dark" content="修改地址" placement="top">
 <el-button size="mini" type="primary" icon="el-icon-edit" @click="showBox"></el-button>
    </el-tooltip>
    <el-tooltip class="item" effect="dark" content="物流进度" placement="top">
            <el-button size="mini" type="success" icon="el-icon-location" @click="showProgressBox"></el-button>
            </el-tooltip>
            </template>
      </el-table-column>
      </el-table>
      <!--分页-->
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="queryinfo.pagenum"
      :page-sizes="[5,10, 15, 20 ]"
      :page-size="queryinfo.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
 </el-card>
<!--修改地址对话框-->
<el-dialog
  title="修改地址"
  :visible.sync="editVisible"
  width="50%" 
  @close="closeedit()">
  <el-form :model="editruleForm" :rules="editrules" ref="ruleForm" label-width="100px" >
  <el-form-item label="省市区/县" prop="address1">
    <el-cascader
    v-model="editruleForm.address1"
    :options="citedate"
    :props="{ expandTrigger: 'hover',label: 'label',value: 'value',children: 'children'}"></el-cascader>
  </el-form-item>
  <el-form-item label="详细地址" prop="address2">
    <el-input v-model="editruleForm.address2"></el-input>
  </el-form-item>
  </el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="editVisible = false">取 消</el-button>
    <el-button type="primary" @click="editVisible = false">确 定</el-button>
  </span>
</el-dialog>
<!--物流进度对话框-->
<el-dialog
  title="物流进度"
  :visible.sync="wldialogVisible"
  width="50%">
  <el-timeline >
    <el-timeline-item
      v-for="(item, index) in progressinso"
      :key="index"
      :timestamp="item.time">
      {{item.context}}
    </el-timeline-item>
  </el-timeline>
  <span slot="footer" class="dialog-footer">
    <el-button @click="wldialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="wldialogVisible = false">确 定</el-button>
  </span>
</el-dialog>
    </div>
    </template>

<script>
 import citedate from './citydata.js'

export default {
    data() {
        return {
            queryinfo: {
                query: '',
                pagenum: 1,
                pagesize: 10
            },
            total: 0,
            //订单列表数据
            orderList: [],
            //对话框的显示与隐藏
            editVisible: false,
            wldialogVisible: false,
            //修改地址表单数据
            editruleForm: {
                address1: [],
                address2: ''
            },
            //验证
            editrules: {
                address1: [{required: true,message: "请选择省市区/县",trigger: 'blur'}],
                address2: [{required: true,message: "请输入详细地址",trigger: 'blur'}]
            },
            //省市数据
            citedate: citedate,
            //物流信息数据
            progressinso: []
        }
    },
    created() {
        this.getOrderList()
    },
    methods: {
        //获取订单列表
        async getOrderList() {
            let { data } = await this.$http.get("orders", { params: this.queryinfo })
            // console.log(data)
            if (data.meta.status !== 200) return this.$message.error("订单列表获取失败")
            this.orderList = data.data.goods
            this.total = data.data.total
        },
        //pagesize改变
        handleSizeChange(news){
          this.queryinfo.pagesize=news
          this.getOrderList()
        },
        //pagenum改变
        handleCurrentChange(news){
         this.queryinfo.pagenum=news
         this.getOrderList()
        },
     //点击修改地址
     showBox(){
        this.editVisible=true
     },
     //关闭对话框
     closeedit(){
        this.$refs.ruleForm.resetFields()
     },
    
     //点击物流进度
    async showProgressBox(){
        let {data}=await this.$http.get("/kuaidi/1106975712662")
        // console.log(data)
        if(data.meta.status!==200) return this.$message.error("获取物流信息失败")
        this.progressinso=data.data
         this.wldialogVisible=true
     }
    }
}
</script>

<style lang="less" scoped>
.el-cascader{
   width: 100%
}
</style>